//首页商品列表
'use strict';
import React,{Component} from 'react';
import styles from '../style/styles';
import GoodsInfo from '../goods/goodsIndex';
import GoodsList from '../goods/goodsList'
import {
    View,
    Text,
    Image,
    TouchableOpacity,
    ListView,
} from 'react-native'

export default class HomeGoodsList extends Component{
    // 构造
      constructor(props) {
        super(props);
          this.state = {

          }
      }


      toGoodsIndex(goods_id){
          this.props.navigator.push({
              component:GoodsInfo,
              passProps:{
                  goods_id:goods_id
              }
          })
      }


      toGoodsList(cate_id,cate_name){
          this.props.navigator.push({
              component:GoodsList,
              passProps:{
                  cate_id:cate_id,
                  title:cate_name
              }
          })
      }


      render(){
          let indexData = this.props.indexData
          return(
              <View>
                  {
                      indexData.goods_cate_list.map((item,index)=>{
                          return(
                              <View key={index}>
                                  <View style={styles.cate_goods_header}>
                                    <Text style={{fontSize:16,color:"#333"}}>{item.cate_name}</Text>
                                      <Text onPress={()=>this.toGoodsList(item.cate_id,item.cate_name)} style={{fontSize:14,color:"#969696"}}>更多></Text>
                                  </View>
                                  <View style={styles.cate_goods_list}>
                                      {
                                          item.goods_list.map((goods,index2)=>{
                                              return(
                                                  <TouchableOpacity onPress={()=>this.toGoodsIndex(goods.goods_id)} key={index2} style={styles.cate_goods_item}>
                                                      <Image
                                                          source={{uri:goods.default_image}}
                                                          style={styles.cate_goods_img}
                                                          resizeMode={'cover'}
                                                      />
                                                      <View style={styles.cate_goods_txt_view}>
                                                          <Text style={{fontSize:14,color:"#333"}} numberOfLines={2}>{goods.goods_name}</Text>
                                                          <View style={styles.cate_goods_price_view}>
                                                              <Text style={{fontSize:16,color:"#f00"}}>¥{goods.price}</Text>
                                                              <Text style={{fontSize:12,color:"#969696",textDecorationLine:'line-through'}}>¥{goods.market_price}</Text>
                                                          </View>
                                                      </View>
                                                  </TouchableOpacity>
                                              )
                                          })
                                      }
                                  </View>
                              </View>
                          )
                      })
                  }
              </View>
          )
      }

}
